import hashlib
# 密码加密
# 文件的一致性校验

# 密码加密
# md5
# ret = hashlib.md5()
# ret.update('123'.encode('utf-8'))
# s = ret.hexdigest()
# print(s,type(s))

# ret = hashlib.md5()
# ret.update('123'.encode('utf-8'))
# s = ret.hexdigest()
# print(s,type(s))
#
# ret = hashlib.md5()
# ret.update('223'.encode('utf-8'))
# s = ret.hexdigest()
# print(s,type(s))

# ret = hashlib.md5()
# ret.update('22fdslkafjdsklfdsjalfaklfjdslkfjdslkfjdsalf;dsajkfldsjf3'.encode('utf-8'))
# s = ret.hexdigest()
# print(s,type(s))

# 撞库

# ret = hashlib.md5()
# ret.update('123456*@qwe'.encode('utf-8'))
# s = ret.hexdigest()
# print(s,type(s))

# 加固定盐
# ret = hashlib.md5('xxx教育'.encode('utf-8'))
# ret.update('123456'.encode('utf-8'))
# s = ret.hexdigest()
# print(s,type(s))

# 加动态的盐
# username = input('输入用户名:').strip()
# password = input('输入密码').strip()
# ret = hashlib.md5(username[::2].encode('utf-8'))
# ret.update(password.encode('utf-8'))
# s = ret.hexdigest()
# print(s)

# sha系列: 安全系数高,耗时高.
# 加盐,加动态盐
# ret = hashlib.sha512()
# ret.update('123456fdklsajflsdfjsdlkafjafkl'.encode('utf-8'))
# s = ret.hexdigest()
# print(s,type(s))
#



# 文件的一致性校验

# low版
# import hashlib
# ret = hashlib.md5()
# with open('MD5文件校验',mode='rb') as f1:
#     content = f1.read()
#     ret.update(content)
# print(ret.hexdigest())
#
# ret = hashlib.md5()
# with open('MD5文件校验1',mode='rb') as f1:
#     content = f1.read()
#     ret.update(content)
# print(ret.hexdigest())

# ret = hashlib.md5()
# with open(r'D:\s23\day17\python-3.7.4rc1-embed-win32.zip',mode='rb') as f1:
#     content = f1.read()
#     ret.update(content)
# print(ret.hexdigest())
# d9c18c989c474c7629121c9d59cc429e
# d9c18c989c474c7629121c9d59cc429e


# 分步update
# s1 = '老男孩教育 最好的python 讲师 是 太白'
#
# # 1
# ret = hashlib.md5()
# ret.update(s1.encode('utf-8'))
# print(ret.hexdigest())
#
#
# # 2
# ret = hashlib.md5()
# ret.update('老男孩教育'.encode('utf-8'))
# ret.update(' 最好的python'.encode('utf-8'))
# ret.update(' 讲师 是'.encode('utf-8'))
# ret.update(' 太白'.encode('utf-8'))
# print(ret.hexdigest())  # 90c56d265a363292ec70c7074798c913
#


# with open(r'D:\s23\day17\read回顾',encoding='utf-8') as f1:
#
#     # print(f1.read(10))
#     # print(f1.read(10))
#     # print(f1.read(10))
#     # while 1:
#     #     print(f1.read(10))
#     print(f1.read(1024))

import hashlib
def md5_file(path):
    ret = hashlib.md5()
    with open(path,mode='rb') as f1:
        while 1:
            content = f1.read(1024)
            if content:
                ret.update(content)
            else:
                return ret.hexdigest()


print(md5_file(r'D:\s23\day17\python-3.7.4rc1-embed-win32.zip'))